﻿using System;
using System.Windows.Forms;

namespace NExplorer.Controls
{
    internal sealed class ExplorerToolBarButton : ToolStripButton, IToolBarButton
    {
        private readonly ToolStripItemCommandManager _manager;
        private readonly Keys _keys;

        public ExplorerToolBarButton(ICommand command)
            : this(command, Keys.None)
        { }

        public ExplorerToolBarButton(ICommand command, Keys keys)
        {
            _manager = new ToolStripItemCommandManager(this, command, keys);
            _keys = keys;
        }

        public Keys Keys
        {
            get { return _keys; }
        }

        public ICommand Command
        {
            get { return _manager.Command; }
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            _manager.ExecuteCommand();
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            _manager.Dispose();
        }
    }
}
